package com.ruoyi.cla.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cla.domain.Cla;
import com.ruoyi.cla.service.IClaService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 分类表Controller
 * 
 * @author ruoyi
 * @date 2025-06-03
 */
@RestController
@RequestMapping("/cla/cla")
public class ClaController extends BaseController
{
    @Autowired
    private IClaService claService;

    /**
     * 查询分类表列表
     */
    @PreAuthorize("@ss.hasPermi('cla:cla:list')")
    @GetMapping("/list")
    public TableDataInfo list(Cla cla)
    {
        startPage();
        List<Cla> list = claService.selectClaList(cla);
        return getDataTable(list);
    }

    @GetMapping("/listCA")
    public TableDataInfo list1(Cla cla)
    {
        startPage();
        List<Cla> list = claService.selectClaArticleList(cla);
        return getDataTable(list);
    }
    /**
     * 导出分类表列表
     */
    @PreAuthorize("@ss.hasPermi('cla:cla:export')")
    @Log(title = "分类表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Cla cla)
    {
        List<Cla> list = claService.selectClaList(cla);
        ExcelUtil<Cla> util = new ExcelUtil<Cla>(Cla.class);
        util.exportExcel(response, list, "分类表数据");
    }

    /**
     * 获取分类表详细信息
     */
    @PreAuthorize("@ss.hasPermi('cla:cla:query')")
    @GetMapping(value = "/{claid}")
    public AjaxResult getInfo(@PathVariable("claid") Long claid)
    {
        return AjaxResult.success(claService.selectClaByClaid(claid));
    }

    /**
     * 新增分类表
     */
    @PreAuthorize("@ss.hasPermi('cla:cla:add')")
    @Log(title = "分类表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Cla cla)
    {
        return toAjax(claService.insertCla(cla));
    }

    /**
     * 修改分类表
     */
    @PreAuthorize("@ss.hasPermi('cla:cla:edit')")
    @Log(title = "分类表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Cla cla)
    {
        return toAjax(claService.updateCla(cla));
    }

    /**
     * 删除分类表
     */
    @PreAuthorize("@ss.hasPermi('cla:cla:remove')")
    @Log(title = "分类表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{claids}")
    public AjaxResult remove(@PathVariable Long[] claids)
    {
        return toAjax(claService.deleteClaByClaids(claids));
    }
}
